﻿package com.uprr.app.tnm.test
{
    import com.uprr.app.tnm.model.Model;
    import com.uprr.app.tnm.views.MyControlBar;

    import flash.events.MouseEvent;

    import mx.events.CollectionEvent;
    import mx.events.CollectionEventKind;

    import net.digitalprimates.fluint.sequence.SequenceEventDispatcher;
    import net.digitalprimates.fluint.sequence.SequenceRunner;
    import net.digitalprimates.fluint.sequence.SequenceSetter;
    import net.digitalprimates.fluint.tests.TestCase;

    public class MyControlBarTest extends TestCase
    {

        public function MyControlBarTest()
        {
            super();
        }

        private var m_myControlBar:MyControlBar;

        override protected function setUp():void
        {
            m_myControlBar = new MyControlBar();
            addChild(m_myControlBar);
        }

        public function testMyControlBar():void
        {
            Model.instance.arrcol.removeAll();
            Model.instance.arrcol.addEventListener(CollectionEvent.COLLECTION_CHANGE, asyncHandler(collectionChangeHandler, 3000, null, timeoutHandler));

            const seqRun:SequenceRunner = new SequenceRunner(this);
            seqRun.addStep(new SequenceSetter(m_myControlBar.col1, {text:"hello"}));
            seqRun.addStep(new SequenceSetter(m_myControlBar.col2, {text:"world"}));
            seqRun.addStep(new SequenceEventDispatcher(m_myControlBar.addBtn, new MouseEvent(MouseEvent.CLICK)));
            seqRun.run();
        }

private function collectionChangeHandler(event:CollectionEvent, data:Object):void
{
    if (event.kind == CollectionEventKind.ADD)
    {
        assertEquals(1, Model.instance.arrcol.length);
        const obj:Object = Model.instance.arrcol.getItemAt(0);
        assertEquals("hello", obj.col1);
        assertEquals("world", obj.col2);
    }
}

        private function timeoutHandler(data:Object):void
        {
            fail("Did not receive an ADD event");
        }

        override protected function tearDown():void
        {
            removeChild(m_myControlBar);
            m_myControlBar = null;
        }

    }
}

